package com.onepower.core.utils;

import com.onepower.core.domain.AuthUser;
//import org.springframework.security.core.context.SecurityContextHolder;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Random;

public class SecurityUtils {

    public static Integer getCurrentUserId(HttpServletRequest request) {
            try {
                String token = getToken(request);
                String tokenStr = SecurityUtil.getDecryptString(token,"tkdMatch");
                Map<String,Object> userMap = JsonUtil.getInstance().json2Object(tokenStr, Map.class);
                return (Integer) userMap.get("id");
            }catch (Exception e){
                e.printStackTrace();
            }

       return null;
    }

    public static Integer getCurrentUserId() {
        return null;
    }

    public static String getToken(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("Authorization");
        return token;
    }

    public static String generatorPass() {
        int pwd = new Random().nextInt(900000) + 100000;
        return Integer.toString(pwd);
    }


}